package com.example.zk2_lx.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.zk2_lx.R;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;

import java.util.List;

public class ConsAdapter extends BaseQuickAdapter<EMConversation, BaseViewHolder> {
    public ConsAdapter(int layoutResId, @Nullable List<EMConversation> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, EMConversation conversation) {
        holder.setText(R.id.tv_name,conversation.conversationId());
        //先判断类型，在强转
        if(conversation.getLastMessage().getType()== EMMessage.Type.TXT){
            String message = ((EMTextMessageBody) (conversation.getLastMessage().getBody())).getMessage();
            holder.setText(R.id.tv_msg,message);
        }else{
            holder.setText(R.id.tv_msg,"非文本消息");
        }
    }
}
